package java101.Cheats;

public class RecursionExample {

	private static int fibCount = 0;

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		//Recursion is doing something that depends on the result before it.
		//Fibonacci is an example of recursion.
		//stackoverflow.com for stack overflow questions.
		
		long start = System.currentTimeMillis();
		System.out.println(fib(33));
		long stop = System.currentTimeMillis();
		System.out.println("fib got called " + fibCount + " times in " + (stop-start) + "ms.");
	}

	private static int fib(int i) {
		fibCount ++;
		if (i < 2)
			return i;
		else
			return fib(i-2) + fib(i-1);
	}

}
